function site_url(uri, key)  {
    if (key == true) {
        uri = uri + '/key/' + SESSION_KEY + '/page.html';
    }
    uri = BASE_URL + uri;
    return uri;
}

var admin_layout = {};
admin_layout.show_type_block = function(type) {
    switch (type) {
        case "select":
            $("#option_block").show();
            break;
        default:
            $("#option_block").hide();
            break;
    }
    return false;
};

var btn_util = {};
btn_util.confirm = function(message, url) {
    var is_ok = confirm(message);
    if (is_ok) {
        window.location = url;
    }
    return;
};
btn_util.check_all = function(checked, selector) {
    $(selector).each(function() {
        $(this).attr("checked", checked);
        if (checked) {
            $(this).parent().parent().addClass("selected");
        } else {
            $(this).parent().parent().removeClass("selected");
        }
    });
    return false;
};
btn_util.check_url = function(selector) {
    var item = $(selector);
    if ($(item).size() == 0) {
        return false;
    }
    var url = $.trim($(item).val()).toString();
    if (url.length == 0) {
        return false;
    }
    window.open(BASE_URL + url);
    return false;
};

btn_util.active_delete = function(item) {
    var message = $(item).attr("message");
    var action = $(item).attr("action");
    var is_delete = window.confirm(message);
    if (is_delete) {
        window.location = action;
    }
    return false;
};

btn_util.toggle_expand = function(header) {
    if ($(header).find(".icon_exp").size() > 0) {
        $(header).find(".icon_exp").toggleClass("icon_dexp");
    }
    $(header).parent().find(".db_inner_content").toggle();
    return false;
};

btn_util.toggle_expand_all = function(item, selector) {
    var expanded = parseInt($(item).attr("data-expand"));
    if (expanded == 0) {
        $(selector).find(".icon_exp").removeClass("icon_dexp");
        $(selector).find(".db_inner_content").hide();
        $(item).attr("data-expand", 1);
    } else {
        $(selector).find(".icon_exp").addClass("icon_dexp");
        $(selector).find(".db_inner_content").show();
        $(item).attr("data-expand", 0);
    }
    return false;
};

function reload_selected() {
    $(".gridview tbody tr td :checkbox").each(function() {
        var checked = $(this).attr("checked");
        if (checked) {
            $(this).parent().parent().addClass("selected");
        } else {
            $(this).parent().parent().removeClass("selected");
        }
    });
}